home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.4)
-
- from test.test_support import TESTFN, TestFailed
- import os
- import random
- import sys
- import py_compile
-
- try:
- import RAnDoM
- except ImportError:
- pass
-
- raise TestFailed('import of RAnDoM should have failed (case mismatch)')
- import double_const
-
- def remove_files(name):
- for f in (name + os.extsep + 'py', name + os.extsep + 'pyc', name + os.extsep + 'pyo', name + os.extsep + 'pyw', name + '$py.class'):
- if os.path.exists(f):
- os.remove(f)
- continue
-
-
-
- def test_with_extension(ext):
- source = TESTFN + ext
- pyo = TESTFN + os.extsep + 'pyo'
- if sys.platform.startswith('java'):
- pyc = TESTFN + '$py.class'
- else:
- pyc = TESTFN + os.extsep + 'pyc'
- f = open(source, 'w')
- print >>f, "# This tests Python's ability to import a", ext, 'file.'
- a = random.randrange(1000)
- b = random.randrange(1000)
- print >>f, 'a =', a
- print >>f, 'b =', b
- f.close()
-
- try:
- mod = __import__(TESTFN)
- except ImportError:
- err = None
- raise ValueError('import from %s failed: %s' % (ext, err))
-
-
- if mod.a != a or mod.b != b:
- print a, '!=', mod.a
- print b, '!=', mod.b
- raise ValueError('module loaded (%s) but contents invalid' % mod)
- os.unlink(source)
-
- try:
- reload(mod)
- except ImportError:
- err = mod.b != b
- raise ValueError('import from .pyc/.pyo failed: %s' % err)
- finally:
-
- try:
- os.unlink(pyc)
- except os.error:
- mod.b != b
-
-
- try:
- os.unlink(pyo)
- except os.error:
- mod.b != b
-
- del sys.modules[TESTFN]
-
-
- sys.path.insert(0, os.curdir)
-
- try:
- test_with_extension(os.extsep + 'py')
- if sys.platform.startswith('win'):
- for ext in ('.PY', '.Py', '.pY', '.pyw', '.PYW', '.pYw'):
- test_with_extension(ext)
-
- finally:
- del sys.path[0]
-
- import imp
- x = imp.find_module('os')
- os = imp.load_module('os', *x)
-
- def test_module_with_large_stack(module):
- filename = module + os.extsep + 'py'
- f = open(filename, 'w+')
- f.write('d = [\n')
- for i in range(65000):
- f.write('"",\n')
-
- f.write(']')
- f.close()
- f = open(filename, 'r')
- py_compile.compile(filename)
- f.close()
- os.unlink(filename)
- sys.path.append('')
- exec 'import ' + module
- del sys.path[-1]
- for ext in ('pyc', 'pyo'):
- fname = module + os.extsep + ext
- if os.path.exists(fname):
- os.unlink(fname)
- continue
-
-
- test_module_with_large_stack('longlist')
-
- def test_failing_import_sticks():
- source = TESTFN + os.extsep + 'py'
- f = open(source, 'w')
- print >>f, 'a = 1/0'
- f.close()
- sys.path.insert(0, os.curdir)
-
- try:
- for i in (1, 2, 3):
-
- try:
- mod = __import__(TESTFN)
- except ZeroDivisionError:
- if TESTFN in sys.modules:
- raise TestFailed('damaged module in sys.modules', i)
-
- TESTFN in sys.modules
-
- raise TestFailed('was able to import a damaged module', i)
- finally:
- sys.path.pop(0)
- remove_files(TESTFN)
-
-
- test_failing_import_sticks()
-
- def test_failing_reload():
- source = TESTFN + os.extsep + 'py'
- f = open(source, 'w')
- print >>f, 'a = 1'
- print >>f, 'b = 2'
- f.close()
- sys.path.insert(0, os.curdir)
-
- try:
- mod = __import__(TESTFN)
- if TESTFN not in sys.modules:
- raise TestFailed('expected module in sys.modules')
-
- if mod.a != 1 or mod.b != 2:
- raise TestFailed('module has wrong attribute values')
-
- remove_files(TESTFN)
- f = open(source, 'w')
- print >>f, 'a = 10'
- print >>f, 'b = 20//0'
- f.close()
-
- try:
- reload(mod)
- except ZeroDivisionError:
- pass
-
- raise TestFailed('was able to reload a damaged module')
- mod = sys.modules.get(TESTFN)
- if mod is None:
- raise TestFailed('expected module to still be in sys.modules')
-
- if mod.a != 10 or mod.b != 2:
- raise TestFailed('module has wrong attribute values')
- finally:
- sys.path.pop(0)
- remove_files(TESTFN)
- if TESTFN in sys.modules:
- del sys.modules[TESTFN]
-
-
-
- test_failing_reload()
-